<?php
	// On prolonge la session
	session_start();
	$id_anim='';
	$code='';
	
	require_once dirname(__FILE__) . "/../../includes/config.php";
	require_once PHP_ROOTPATH.'/classes/database.php';
	
	
		// On teste si la variable de session existe et contient une valeur
		if(empty($_SESSION['id_anim'])){
			// Si inexistante ou nulle, on redirige vers la page de saisie du code
			header('Location: ../recherche.php');
			exit();
		}
		else{
			$id_anim=$_SESSION['id_anim'];
			$code=$_SESSION['code'];
		}
	
?>

<!DOCTYPE html>
<html>
	<head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="../../style.css" />
		<!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <!--[if lte IE 7]>
        <link rel="stylesheet" href="../../style_ie.css" />
        <![endif]-->
        <title>Base de données microcèbes</title>
        
        <script type="text/javascript">
			function afficher(oSelect){
				var id=oSelect.id;
				var elt = document.getElementById(id);
				if(elt.style.display=="block"){
					elt.style.display="none";
				}
				else{
					elt.style.display="block";
				}
			}
		</script>
    </head>
    
    <body>
		<?php include((dirname(dirname(dirname(__FILE__))))."/menu.php"); ?>
		<?php include((dirname(dirname(__FILE__)))."/calcul_age.php"); ?>
		<section id="main">
			<header>
				<h1>Recherche -Génotypage/Séquençage animal <?php echo $code;?></h1>
			</header>
			<?php include((dirname(dirname(__FILE__)))."/menu_recherche.php"); ?>
			<section id="animal">
				<div id="menu3">
					<ul id="onglets">
						<li class="active"><a href="genotype.php">Génotypage</a></li>
						<li><a href="seq.php">Séquençage</a></li>
					</ul>
				</div>
				<section id="contenu">
					<?php                 
						$idconnect=Database::getInstance();
						 
						$query=pg_query($idconnect,"SELECT date_test,experimentateur,code_marqueur,localisation,allele1,allele2,allele3,genotype
						FROM test_genotypage,resultat_test,test,type_test 
						WHERE label LIKE '%Génotypage%' AND id_animal='".$id_anim."'
						AND test_genotypage.id_res=resultat_test.id_res
						AND resultat_test.id_test=test.id_test AND test.id_type_test=type_test.id_type_test");
						$int = pg_num_rows($query);
						if($int==0){echo("<p><label>Pas d'informations disponibles</label></p>");}
						else{
							while ($back = pg_fetch_assoc($query)) {
								echo "<div><label class=\"titre2\">".$back["code_marqueur"]."</label><input type=\"button\" onclick=\"afficher(".$back["code_marqueur"].")\" value=\"Détail\"></div>";
								echo "<p class='autre' id=\"".$back["code_marqueur"]."\">";
								if($back["date_test"]){echo "<label><strong>Date du test: </strong>".date("d/m/Y", strtotime($back["date_test"]))."</label><br/>";}
								if($back["experimentateur"]){echo "<label><strong>Expérimentateur: </strong>".$back["experimentateur"]."</label><br/>";}
								if($back["localisation"]){echo "<label><strong>Localisation: </strong>".$back["localisation"]."</label><br/>";}
								if($back["allele1"]){echo "<label><strong>Allele 1 : </strong>".$back["allele1"]."</label><br/>";}
								if($back["allele2"]){echo "<label><strong>Allele 2 : </strong>".$back["allele2"]."</label><br/>";}
								if($back["allele3"]){echo "<label><strong>Allele 3 : </strong>".$back["allele3"]."</label><br/>";}
								if($back["genotype"]){echo "<label><strong>Génotype : </strong>".$back["genotype"]."</label><br/>";}
								echo "</p>";
							}
						}
					?>		
				</section>
			</section>
		</section>
	</body>
</html>
